package com.itheima.solr;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.junit.Test;

public class SolrQueryTest {
    @Test
    public void QueryTest() throws SolrServerException {
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");
        SolrQuery solrQuery = new SolrQuery("title:手机");
        //发送web请求
        QueryResponse response = solrServer.query(solrQuery);
        //获取查询结果
        SolrDocumentList results = response.getResults();
        for (SolrDocument result : results) {
            String id = (String) result.get("id");
            String title = (String) result.get("title");
            Long price = (Long) result.get("price");
            System.out.println("id:" + id + " title" + title + " price" + price);
        }
    }
}
